<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="4">
        <div class="nav">
            <div class="title">产品类型列表</div>
           <TreeProduct @sendetreedata="sendetreedata"></TreeProduct>
        </div></el-col>
      <el-col :span="20">
        <div class="wrapper">
            <div class="title">商品添加</div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
               <el-form-item label="所属类目" prop="category">
                <span>{{ruleForm.category}}</span>
   
  </el-form-item>
  <el-form-item label="商品名称" prop="title">
    <el-input v-model="ruleForm.title"></el-input>
  </el-form-item>
  <el-form-item label="商品价格" prop="price">
    <el-input v-model="ruleForm.price"></el-input>
  </el-form-item>
  <el-form-item label="商品数量" prop="num">
    <el-input v-model="ruleForm.num"></el-input>
  </el-form-item>
  <el-form-item label="商品卖点" prop="sellPoint">
    <el-input v-model="ruleForm.sellPoint"></el-input>
  </el-form-item>
   <el-form-item label="商品图片" prop="image">
     <UploadImg></UploadImg>
  </el-form-item>
  <el-form-item label="商品描述" prop="descs">
    <WangEditor></WangEditor>
  </el-form-item>
  <el-form-item label="首页轮播推荐" prop="isShow">
    <el-switch v-model="ruleForm.isShow"  active-color="#13ce66"
    inactive-color="#ff4949"></el-switch>
  </el-form-item>
  <el-form-item label="是否推荐商品" prop="isShow">
    <el-switch v-model="ruleForm.isShow"  active-color="#13ce66"
    inactive-color="#ff4949"></el-switch>
  </el-form-item>
  <el-form-item label="是否上架商品" prop="isShow">
    <el-switch v-model="ruleForm.isShow"  active-color="#13ce66"
    inactive-color="#ff4949"></el-switch>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
    <el-button >取消</el-button>
  </el-form-item>
</el-form>
        </div>
        </el-col>
    </el-row>
  </div>
</template>

<script>

import TreeProduct from './TreeProduct.vue'
import UploadImg from './UploadImg.vue'
import WangEditor from './WangEditor.vue'
export default {
    data() {
      return {
        ruleForm: {
          title:'',
          num:'',
          price:'',
          sellPoint:'',
          image:[],
          descs:'',
          category:'',
          cid:'',
         isShow:true

        },
        rules: {
          title: [
            { required: true, message: '请输入商品名称', trigger: 'blur' },
           
          ],
          num: [
            { required: true, message: '请输入商品数量', trigger: 'blur' },
          ],
          price: [
            { required: true, message: '请输入商品价格', trigger: 'blur' },
          ],
         
        }
      };
    },
    methods: {
      sendetreedata(val){
     
       this.ruleForm.category = val.name
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
             this.$router.push('/product/list')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
       
      }
    },
  components:{
    TreeProduct,
    UploadImg,
    WangEditor
  }
};
</script>

<style scoped>
.nav {
  height: 600px;
  background-color: rgb(255, 255, 255);
}
.wrapper {
  
  background-color: rgb(255, 255, 255);
}
.title{
  height: 50px;
  line-height: 50px;
  background: gray;
}
.demo-ruleForm{
  padding: 20px;
}
</style>>
  

